package com.lsy.weizhi2.activity;

import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.ViewTreeObserver;
import android.widget.GridView;
import android.widget.LinearLayout;

import com.lsy.weizhi2.R;
import com.lsy.weizhi2.adapter.WeiYouImageAdapter;
import com.lsy.weizhi2.config.MyHeight;
import com.lsy.weizhi2.mybase.MyBaseActivity;
import com.lsy.weizhi2.mybase.MyTitleView;

public class AllWeiYou extends MyBaseActivity {
    private Context context;
    private MyTitleView allweiyou_title;
    private GridView allweiyou_gv;
    private WeiYouImageAdapter weiYouImageAdapter;
    private int xx;
    private Handler handler=new Handler();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_all_wei_you);
        context=AllWeiYou.this;
        String name=getIntent().getStringExtra("name");
        allweiyou_title= (MyTitleView) findViewById(R.id.allweiyou_title);
        allweiyou_gv= (GridView) findViewById(R.id.allweiyou_gv);
        if(name!=null){
            allweiyou_title.setTitle(name);
        }
        weiYouImageAdapter=new WeiYouImageAdapter(context,null);
        allweiyou_gv.setAdapter(weiYouImageAdapter);

    }

    @Override
    protected void onResume() {
        super.onResume();
        xx=0;
        new Thread(new Runnable() {
            @Override
            public void run() {
                ViewTreeObserver vto = allweiyou_title.getViewTreeObserver();
                vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        if (xx < 1) {
                            xx++;
                            handler.post(new Runnable() {
                                @Override
                                public void run() {
                                    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(allweiyou_title.getLayoutParams());
                                    params.height = MyHeight.ACTIONBAR + MyHeight.MyTitleHeight;
                                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                                        allweiyou_title.setLayoutParams(params);
                                    }
                                }
                            });
                        }
                    }
                });
            }
        }).start();
    }
}
